package com.xzz.dp;

/**
 * @author: hhz
 * @create: 2022-01-20 13:26
 * 343. 整数拆分
 **/
public class IntegerBreak {
    public static void main(String[] args) {
        System.out.println(integerBreak(2));
        System.out.println(integerBreak(10));
    }
    public static int integerBreak(int n) {
        //定义dp[i]表示将i拆分成至少两个正整数的和，这些整数的最大乘积为dp[i]
        int[] dp = new int[n+1];
        dp[2] = 1;
        for (int i = 3; i <= n; i++) {
            for (int j = 1; j < i-1; j++) {
                dp[i] = Math.max(dp[i], Math.max((i - j) * j, dp[i - j] * j));
            }
        }
        return dp[n];

    }
}
